package com.net.framework.help.utils;

/**
 * @author zhangxiaobin
 * @email zhangxiaobin@yipintech.com
 * @date 创建时间：2016年1月11日 下午2:28:44
 * @version 1.1.0
 * @explain 说明
 */
public class EmojiUtils {

	/**
	 * 检测是否有emoji表情
	 * 
	 * @param source
	 * @return
	 */
	public static boolean containsEmoji(String source) {
		// 首先验证是否为空，为空则直接返回false，不再做验证；否则做验证
		if (StringUtil.isBlank(source)) {
			return false;
		}

		int len = source.length();
		for (int i = 0; i < len; i++) {
			char codePoint = source.charAt(i);
			if (!isEmojiCharacter(codePoint)) { // 如果不能匹配,则该字符是Emoji表情
				return true;
			}
		}
		return false;
	}

	/**
	 * 判断是否是Emoji
	 * 
	 * @param codePoint
	 *            比较的单个字符
	 * @return
	 */
	private static boolean isEmojiCharacter(char codePoint) {
		return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF))
				|| ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF));
	}
}
